using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;

namespace RobotClient.Services
{
    public class TriggerRefreshService : BackgroundService
    {
        private readonly JobScheduler _jobScheduler;

        public TriggerRefreshService(JobScheduler jobScheduler)
        {
            _jobScheduler = jobScheduler;
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                await _jobScheduler.RefreshTriggers();
                await Task.Delay(20000, stoppingToken); // 每20刷新一次
            }
        }
    }
}